import React from 'react'
import {Modal, Toast} from "antd-mobile";
import boxSrc from "../../../../../../res/images/web/together/拆盲盒@2x.png"
import eggSrc from "../../../../../../res/images/web/together/砸金蛋@2x.png"
import './game-popup.css'
import {log} from "../../../../../../utils/commonfunc";
import LocalStorageService from "../../../../../../utils/LocalStorageService";
import {getGameLoginInfo} from "../../../../../../apis/goApis";

class GamePopup extends React.Component {

    constructor(props) {
        super(props)
        this.uid = LocalStorageService.get('userid')
        this.login = LocalStorageService.get('isLogin')
    }

    callGame(name) {
        if (this.login) {
            getGameLoginInfo({
                Uid: this.uid,
                Gametype: name,
            })
                .then(res => {
                    console.log("res", res)
                    if (res.data.ok) {
                        const gameUrl = res.data.ok.gameUrl
                        window.location = gameUrl
                    }
                })
        } else {
            Toast.fail('请登陆')
        }
    }

    render() {

        return <Modal
            popup
            visible={this.props.visible}
            onClose={() => this.props.onClose('game')}
            animationType="slide-up"
        >
            <div
                className='flex-space-around-align-center game-popup-container'
            >
                <div className='game-popup-item' onClick={() => this.callGame('manghe')}>
                    <img src={boxSrc} alt=''/>
                    <p>拆盲盒</p>
                </div>
                <div className='game-popup-item' onClick={() => this.callGame('dianqiu')}>
                    <img src={eggSrc} alt=''/>
                    <p>点球大战</p>
                </div>
            </div>
        </Modal>
    }
}

export default GamePopup